/**
 * @ProjectName:designPatern
 * @Title: SimpleFactoryPattern
 * @Package _02factoryPattern
 * @Description: 简单工厂模式
 * @version V1.0
 * Copyright (c) 2025, 2034279227@qq.com All Rights Reserved.
 */

package _02factoryPattern;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;

/**
 * @author Ssc
 * @data 2025/5/25 22:43
 * 以手机品牌为例
 */
public class SimpleFactoryPattern {

    /**
     * 工厂接收手机需求，进行生产
     * @param supplier
     */
    public static PhoneProduct producePhoneByNeed(String supplier){
        if ("huawei".equals(supplier)){
            return new HwPhoneProductImpl("华为");
        }
        if ("xiaomi".equals(supplier)){
            return new XiaoMiPhoneProductImpl("小米");
        }
        // 正常开发中，此处应该抛出异常，显示无该款手机（但根据实际场景有不同的实现）
        return null;
    }
}

@Data
class HwPhoneProductImpl implements PhoneProduct{

    private String brand;

    /**
     * 生产华为手机
     */
    @Override
    public void producePhone() {
        System.out.println(brand+"手机生产完成");
    }

    public HwPhoneProductImpl(String brand) {
        this.brand = brand;
    }
}

@Data
class XiaoMiPhoneProductImpl implements PhoneProduct{

    /**
     * 手机型号
     */
    private String brand;

    /**
     * 生产小米手机
     */
    @Override
    public void producePhone() {
        System.out.println(brand+"手机生产完成");
    }

    public XiaoMiPhoneProductImpl(String brand) {
        this.brand = brand;
    }
}

interface PhoneProduct{
    void producePhone();
}
